how to count characters in java